package com.m3839.sdk.ym

import android.app.Activity
import android.util.Log
import com.m3839.sdk.ym.core.YMManager
import com.m3839.sdk.ym.ui.YMTipDialogFragment
import com.m3839.sdk.ym.util.YMLogUtils

/**
 * @description: YouthModelSDK->SDK的对外入口
 *
 * @author ChenBaoyang
 * @date 6/1/21 10:26
 */
object YouthModelSDK {

    /**
     * 对外用来给开发者接入-进行初始化sdk
     *
     * @param activity Activity  游戏主activity
     * @param config YouthModelConfig  强少年模式的相关配置
     * @param callback Function2<[@kotlin.ParameterName] Int, [@kotlin.ParameterName] String, Unit>?  回调函数
     */
    fun initSDK(activity: Activity,
                config: YouthModelConfig,
                callback: ((code: Int, message: String) -> Unit)? = null) {
        YMManager.instance.init(activity, config, callback)
        val fcmNotTime: Boolean = YMManager.instance.getFcmNotTime()
        if (fcmNotTime) {
            return
        }

        val hadFcmOpen: Boolean = YMManager.instance.getFcmStatus()
        val remainingTime: Long = YMManager.instance.getRemainingTime()
        if (hadFcmOpen && remainingTime > 0) {
            YMManager.instance.startFcm(remainingTime)
        } else if (hadFcmOpen) {
            YMManager.instance.startFcm(-1)
        } else {
            Log.i("chen34","YMTipDialogFragment-----show")
            YMTipDialogFragment.show(activity)
        }
    }

    /**
     * 对外开放日志控制开关（用于开发者接入调试）
     *
     * @param open Boolean
     */
    fun setDebug(open: Boolean) {
        YMLogUtils.isDebug = open
    }
}